package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SourceSubcategory;
import com.ruoyi.system.service.ISourceSubcategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 来源小类Controller
 *
 * @author ruoyi
 * @date 2025-06-09
 */
@RestController
@RequestMapping("/system/subcategory")
public class SourceSubcategoryController extends BaseController
{
    @Autowired
    private ISourceSubcategoryService sourceSubcategoryService;

    /**
     * 查询来源小类列表
     */
    //@PreAuthorize("@ss.hasPermi('system:subcategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(SourceSubcategory sourceSubcategory)
    {
        startPage();
        List<SourceSubcategory> list = sourceSubcategoryService.selectSourceSubcategoryList(sourceSubcategory);
        return getDataTable(list);
    }

    /**
     * 导出来源小类列表
     */
    @PreAuthorize("@ss.hasPermi('system:subcategory:export')")
    @Log(title = "来源小类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SourceSubcategory sourceSubcategory)
    {
        List<SourceSubcategory> list = sourceSubcategoryService.selectSourceSubcategoryList(sourceSubcategory);
        ExcelUtil<SourceSubcategory> util = new ExcelUtil<SourceSubcategory>(SourceSubcategory.class);
        util.exportExcel(response, list, "来源小类数据");
    }

    /**
     * 获取来源小类详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:subcategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sourceSubcategoryService.selectSourceSubcategoryById(id));
    }

    /**
     * 新增来源小类
     */
    @PreAuthorize("@ss.hasPermi('system:subcategory:add')")
    @Log(title = "来源小类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SourceSubcategory sourceSubcategory)
    {
        return toAjax(sourceSubcategoryService.insertSourceSubcategory(sourceSubcategory));
    }

    /**
     * 修改来源小类
     */
    @PreAuthorize("@ss.hasPermi('system:subcategory:edit')")
    @Log(title = "来源小类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SourceSubcategory sourceSubcategory)
    {
        return toAjax(sourceSubcategoryService.updateSourceSubcategory(sourceSubcategory));
    }

    /**
     * 删除来源小类
     */
    @PreAuthorize("@ss.hasPermi('system:subcategory:remove')")
    @Log(title = "来源小类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sourceSubcategoryService.deleteSourceSubcategoryByIds(ids));
    }
}